<template>
	<section>
		<!--工具条-->
		<el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
			<el-form :inline="true" :model="filters">
				<el-form-item>
					<el-input clearable v-model="filters.date" placeholder="搜索"></el-input>
				</el-form-item>

				<el-form-item>
					<el-button type="primary" v-on:click="search">筛选</el-button>
				</el-form-item>

<!--				<el-form-item>-->
<!--					<el-button type="primary" @click="handleAdd" v-if="userId!=444">添加新用户</el-button>-->
<!--				</el-form-item>-->

			</el-form>

		</el-col>

		<!--列表-->
		<el-table :data="list" highlight-current-row v-loading="listLoading" @selection-change="selsChange" style="width: 100%;">
			<el-table-column prop="user_id" label="用户id" width="150" >
			</el-table-column>
			<el-table-column prop="parent" label="公司域" width="100">
			</el-table-column>
			<el-table-column prop="bet_type" label="类型" width="100">
			</el-table-column>
			<el-table-column prop="match_event" label="赛事" width="200" >
			</el-table-column>
			<el-table-column prop="win_lose" label="本赛状态" width="180" >
			</el-table-column>
			<el-table-column prop="bet_amt" label="下注金额" width="" >
			</el-table-column>
			<el-table-column prop="theory_win_amt" label="可赢" width="" >
			</el-table-column>
			<el-table-column prop="bet_time" label="下注时间" width="250" >
			</el-table-column>
			<el-table-column prop="settle_time" label="结算时间" width="250" >
			</el-table-column>
			<el-table-column prop="lottery_result" label="结算结果" width="" >
			</el-table-column>
			<el-table-column prop="give_rewards" label="发放金额" width="" >
			</el-table-column>
			<el-table-column prop="event_end_time" label="赛事结束时间" width="250" >
			</el-table-column>

			<el-table-column label="操作" width="300">
				<template scope="scope">
					<el-button size="small" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
					<el-button type="danger" size="small" @click="handleDel(scope.$index, scope.row)">删除</el-button>
				</template>
			</el-table-column>
		</el-table>

		<el-col :span="24" class="toolbar">
			<el-pagination v-if="total != 0" layout="prev, pager, next" :current-page.sync="current" @current-change="handleCurrentChange" :page-size="limit" :total="total" style="float:right;">
			</el-pagination>
		</el-col>



	</section>
</template>

<script>
	import { betSlipSomeone} from '../../api/api';

	export default {
		data() {
			return {
				host:this.GLOBAL.host,
				current:1,
				token:'',
				userId:'',

				password:'',
				filters: {
					date: '',
					user_id: '',
				},
				list: [],
				total: 0,
				limit:10,
				page: 1,
				listLoading: false,
				sels: [],//列表选中列


			}
		},
		methods: {
			handleCurrentChange(val) {
				this.page = val;
				this.current = val;
				this.getList();
			},
			search(){
				this.page = 1;
				this.current = 1;
				this.getList();
			},
			getList() {
				let para = {
					user_id:this.filters.user_id?this.filters.user_id:"12345test123",
					date:this.filters.date?this.filters.date:"",
					page: {
						num:this.page,
						size:10,
					}
				};

				this.listLoading = true;
				betSlipSomeone(para).then((res) => {
					this.listLoading = false;
					let { message, code, data } = res;
					if(code != 200){
						this.$message({
							message: message?message:'请求失败',
							type: 'error'
						});
						return false;
					}

					this.total = data.page.total;
					this.list = data.List;

				});
			},
			//删除
			handleDel: function (index, row) {
				this.$confirm('确认删除该记录吗?', '提示', {
					type: 'warning'
				}).then(() => {
					this.listLoading = true;
					//NProgress.start();
					let para = {
						uid: row.id,
						token:this.token,
						userId:this.userId
					};
					removeUser(para).then((res) => {
						this.listLoading = false;
						//NProgress.done();
						this.$message({
							message: '删除成功',
							type: 'success'
						});
						this.getUsers();
					});
				}).catch(() => {

				});
			},
			//显示编辑界面
			handleEdit: function (index, row) {
				this.editFormVisible = true;
				this.editForm = Object.assign({}, row);
				this.editForm.password = null;
				this.editForm.status = Boolean(row.status);
				this.checkTags = row.tag;
			},
			//显示新增界面
			handleAdd: function () {
				this.addFormVisible = true;
				this.checkTags = [];
				this.addForm = {
					truename: '',
					sex: -1,
					mobile: '',
					note: '',
					role_type: '',
					keshi:[]
				};
			},
			//编辑
			editSubmit: function () {
				this.$refs.editForm.validate((valid) => {
					if (valid) {
						this.$confirm('确认提交吗？', '提示', {}).then(() => {
							let para = Object.assign({}, this.editForm);
							para.userId = this.userId;
							para.token = this.token;
							para.tag = this.checkTags;
							editUser(para).then((res) => {
								this.editLoading = false;

								if(res.data.code != 200){
									this.$message({
										message: res.data.msg?res.data.msg:'未更改',
										type: 'error'
									});
									return false;
								}

								//NProgress.done();
								this.$message({
									message: '提交成功',
									type: 'success'
								});
								this.$refs['editForm'].resetFields();
								this.editFormVisible = false;
								this.getUsers();
							});
						});
					}
				});
			},
			selsChange: function (sels) {
				this.sels = sels;
			},
			toTime1(date){
				this.checkMonth = date;
			},
			exportInfo(){
				var url = this.host+'/api/user/exportInfo?word='+this.filters.name+'&role='+this.filters.role;
				window.location.href = url;
			}

		},

		mounted() {
			// var user = sessionStorage.getItem('user');
			var user = localStorage.getItem('user');
			this.getList();
		}
	}

</script>

<style scoped>
.numbers{
	color: #409EFF;
	cursor: pointer;
}
</style>